home *** CD-ROM | disk | FTP | other *** search
/ Clickx 75 / Clickx 75.iso / software / expressionweb / expressionwebv3 / ExpressionWeb_en.exe / Setup / WeNoLoc.cab / xweb.Silverlight.Silverlight.js < prev    next >
Encoding:
Text File  |  2009-06-09  |  15.2 KB  |  486 lines

  1. ∩╗┐if (!window.Silverlight)
  2. {
  3.     window.Silverlight = { };
  4. }
  5.  
  6. // Silverlight control instance counter for memory mgt
  7. Silverlight._silverlightCount = 0;
  8. Silverlight.fwlinkRoot='http://go2.microsoft.com/fwlink/?LinkID=';  
  9. Silverlight.onGetSilverlight = null;
  10. Silverlight.onSilverlightInstalled = function () {window.location.reload(false);};
  11.  
  12. //////////////////////////////////////////////////////////////////
  13. // isInstalled, checks to see if the correct version is installed
  14. //////////////////////////////////////////////////////////////////
  15. Silverlight.isInstalled = function(version)
  16. {
  17.     var isVersionSupported=false;
  18.     var container = null;
  19.     
  20.     try 
  21.     {
  22.         var control = null;
  23.         
  24.         try
  25.         {
  26.             control = new ActiveXObject('AgControl.AgControl');
  27.             if ( version == null )
  28.             {
  29.                 isVersionSupported = true;
  30.             }
  31.             else if ( control.IsVersionSupported(version) )
  32.             {
  33.                 isVersionSupported = true;
  34.             }
  35.             control = null;
  36.         }
  37.         catch (e)
  38.         {
  39.             var plugin = navigator.plugins["Silverlight Plug-In"] ;
  40.             if ( plugin )
  41.             {
  42.                 if ( version === null )
  43.                 {
  44.                     isVersionSupported = true;
  45.                 }
  46.                 else
  47.                 {
  48.                     var actualVer = plugin.description;
  49.                     if ( actualVer === "1.0.30226.2")
  50.                         actualVer = "2.0.30226.2";
  51.                     var actualVerArray =actualVer.split(".");
  52.                     while ( actualVerArray.length > 3)
  53.                     {
  54.                         actualVerArray.pop();
  55.                     }
  56.                     while ( actualVerArray.length < 4)
  57.                     {
  58.                         actualVerArray.push(0);
  59.                     }
  60.                     var reqVerArray = version.split(".");
  61.                     while ( reqVerArray.length > 4)
  62.                     {
  63.                         reqVerArray.pop();
  64.                     }
  65.                     
  66.                     var requiredVersionPart ;
  67.                     var actualVersionPart
  68.                     var index = 0;
  69.                     
  70.                     
  71.                     do
  72.                     {
  73.                         requiredVersionPart = parseInt(reqVerArray[index]);
  74.                         actualVersionPart = parseInt(actualVerArray[index]);
  75.                         index++;
  76.                     }
  77.                     while (index < reqVerArray.length && requiredVersionPart === actualVersionPart);
  78.                     
  79.                     if ( requiredVersionPart <= actualVersionPart && !isNaN(requiredVersionPart) )
  80.                     {
  81.                         isVersionSupported = true;
  82.                     }
  83.                 }
  84.             }
  85.         }
  86.     }
  87.     catch (e) 
  88.     {
  89.         isVersionSupported = false;
  90.     }
  91.     if (container) 
  92.     {
  93.         document.body.removeChild(container);
  94.     }
  95.     
  96.     return isVersionSupported;
  97. }
  98. Silverlight.WaitForInstallCompletion = function()
  99. {
  100.     if ( ! Silverlight.isBrowserRestartRequired && Silverlight.onSilverlightInstalled )
  101.     {
  102.         try
  103.         {
  104.             navigator.plugins.refresh();
  105.         }
  106.         catch(e)
  107.         {
  108.         }
  109.         if ( Silverlight.isInstalled(null) )
  110.         {
  111.             Silverlight.onSilverlightInstalled();
  112.         }
  113.         else
  114.         {
  115.               setTimeout(Silverlight.WaitForInstallCompletion, 3000);
  116.         }    
  117.     }
  118. }
  119. Silverlight.__startup = function()
  120. {
  121.     Silverlight.isBrowserRestartRequired = Silverlight.isInstalled(null);//(!window.ActiveXObject || Silverlight.isInstalled(null));
  122.     if ( !Silverlight.isBrowserRestartRequired)
  123.     {
  124.         Silverlight.WaitForInstallCompletion();
  125.     }
  126.     if (window.removeEventListener) { 
  127.        window.removeEventListener('load', Silverlight.__startup , false);
  128.     }
  129.     else { 
  130.         window.detachEvent('onload', Silverlight.__startup );
  131.     }
  132. }
  133.  
  134. if (window.addEventListener) 
  135. {
  136.     window.addEventListener('load', Silverlight.__startup , false);
  137. }
  138. else 
  139. {
  140.     window.attachEvent('onload', Silverlight.__startup );
  141. }
  142.  
  143. ///////////////////////////////////////////////////////////////////////////////
  144. // createObject();  Params:
  145. // parentElement of type Element, the parent element of the Silverlight Control
  146. // source of type String
  147. // id of type string
  148. // properties of type String, object literal notation { name:value, name:value, name:value},
  149. //     current properties are: width, height, background, framerate, isWindowless, enableHtmlAccess, inplaceInstallPrompt:  all are of type string
  150. // events of type String, object literal notation { name:value, name:value, name:value},
  151. //     current events are onLoad onError, both are type string
  152. // initParams of type Object or object literal notation { name:value, name:value, name:value}
  153. // userContext of type Object
  154. /////////////////////////////////////////////////////////////////////////////////
  155.  
  156. Silverlight.createObject = function(source, parentElement, id, properties, events, initParams, userContext)
  157. {
  158.     var slPluginHelper = new Object();
  159.     var slProperties = properties;
  160.     var slEvents = events;
  161.     
  162.     slPluginHelper.version = slProperties.version;
  163.     slProperties.source = source;    
  164.     slPluginHelper.alt = slProperties.alt;
  165.     
  166.     //rename properties to their tag property names
  167.     if ( initParams )
  168.         slProperties.initParams = initParams;
  169.     if ( slProperties.isWindowless && !slProperties.windowless)
  170.         slProperties.windowless = slProperties.isWindowless;
  171.     if ( slProperties.framerate && !slProperties.maxFramerate)
  172.         slProperties.maxFramerate = slProperties.framerate;
  173.     if ( id && !slProperties.id)
  174.         slProperties.id = id;
  175.     
  176.     // remove elements which are not to be added to the instantiation tag
  177.     delete slProperties.ignoreBrowserVer;
  178.     delete slProperties.inplaceInstallPrompt;
  179.     delete slProperties.version;
  180.     delete slProperties.isWindowless;
  181.     delete slProperties.framerate;
  182.     delete slProperties.data;
  183.     delete slProperties.src;
  184.     delete slProperties.alt;
  185.  
  186.  
  187.     // detect that the correct version of Silverlight is installed, else display install
  188.  
  189.     if (Silverlight.isInstalled(slPluginHelper.version))
  190.     {
  191.         //move unknown events to the slProperties array
  192.         for (var name in slEvents)
  193.         {
  194.             if ( slEvents[name])
  195.             {
  196.                 if ( name == "onLoad" && typeof slEvents[name] == "function" && slEvents[name].length != 1 )
  197.                 {
  198.                     var onLoadHandler = slEvents[name];
  199.                     slEvents[name]=function (sender){ return onLoadHandler(document.getElementById(id), userContext, sender)};
  200.                 }
  201.                 var handlerName = Silverlight.__getHandlerName(slEvents[name]);
  202.                 if ( handlerName != null )
  203.                 {
  204.                     slProperties[name] = handlerName;
  205.                     slEvents[name] = null;
  206.                 }
  207.                 else
  208.                 {
  209.                     throw "typeof events."+name+" must be 'function' or 'string'";
  210.                 }
  211.             }
  212.         }
  213.         slPluginHTML = Silverlight.buildHTML(slProperties);
  214.     }
  215.     //The control could not be instantiated. Show the installation prompt
  216.     else 
  217.     {
  218.         slPluginHTML = Silverlight.buildPromptHTML(slPluginHelper);
  219.     }
  220.  
  221.     // insert or return the HTML
  222.     if(parentElement)
  223.     {
  224.         parentElement.innerHTML = slPluginHTML;
  225.     }
  226.     else
  227.     {
  228.         return slPluginHTML;
  229.     }
  230.  
  231. }
  232.  
  233. ///////////////////////////////////////////////////////////////////////////////
  234. //
  235. //  create HTML that instantiates the control
  236. //
  237. ///////////////////////////////////////////////////////////////////////////////
  238. Silverlight.buildHTML = function( slProperties)
  239. {
  240.     var htmlBuilder = [];
  241.  
  242.     htmlBuilder.push('<object type=\"application/x-silverlight\" data="data:application/x-silverlight,"');
  243.     if ( slProperties.id != null )
  244.     {
  245.         htmlBuilder.push(' id="' + slProperties.id + '"');
  246.     }
  247.     if ( slProperties.width != null )
  248.     {
  249.         htmlBuilder.push(' width="' + slProperties.width+ '"');
  250.     }
  251.     if ( slProperties.height != null )
  252.     {
  253.         htmlBuilder.push(' height="' + slProperties.height + '"');
  254.     }
  255.     htmlBuilder.push(' >');
  256.     
  257.     delete slProperties.id;
  258.     delete slProperties.width;
  259.     delete slProperties.height;
  260.     
  261.     for (var name in slProperties)
  262.     {
  263.         if (slProperties[name])
  264.         {
  265.             htmlBuilder.push('<param name="'+Silverlight.HtmlAttributeEncode(name)+'" value="'+Silverlight.HtmlAttributeEncode(slProperties[name])+'" />');
  266.         }
  267.     }
  268.     htmlBuilder.push('<\/object>');
  269.     return htmlBuilder.join('');
  270. }
  271.  
  272.  
  273.  
  274.  
  275. // createObjectEx, takes a single parameter of all createObject parameters enclosed in {}
  276. Silverlight.createObjectEx = function(params)
  277. {
  278.     var parameters = params;
  279.     var html = Silverlight.createObject(parameters.source, parameters.parentElement, parameters.id, parameters.properties, parameters.events, parameters.initParams, parameters.context);
  280.     if (parameters.parentElement == null)
  281.     {
  282.         return html;
  283.     }
  284. }
  285.  
  286. ///////////////////////////////////////////////////////////////////////////////////////////////
  287. // Builds the HTML to prompt the user to download and install Silverlight
  288. ///////////////////////////////////////////////////////////////////////////////////////////////
  289. Silverlight.buildPromptHTML = function(slPluginHelper)
  290. {
  291.     var slPluginHTML = "";
  292.     var urlRoot = Silverlight.fwlinkRoot;
  293.     var shortVer = slPluginHelper.version ;
  294.     if ( slPluginHelper.alt )
  295.     {
  296.         slPluginHTML = slPluginHelper.alt;
  297.     }
  298.     else
  299.     {
  300.         if (! shortVer )
  301.         {
  302.             shortVer="";
  303.         }
  304.         slPluginHTML = "<a href='javascript:Silverlight.getSilverlight(\"{1}\");' style='text-decoration: none;'><img src='{2}' alt='Get Microsoft Silverlight' style='border-style: none'/></a>";
  305.         slPluginHTML = slPluginHTML.replace('{1}', shortVer );
  306.         slPluginHTML = slPluginHTML.replace('{2}', urlRoot + '108181');
  307.     }
  308.     
  309.     return slPluginHTML;
  310. }
  311.  
  312.  
  313. Silverlight.getSilverlight = function(version)
  314. {
  315.     if (Silverlight.onGetSilverlight )
  316.     {
  317.         Silverlight.onGetSilverlight();
  318.     }
  319.     
  320.     var shortVer = "";
  321.     var reqVerArray = String(version).split(".");
  322.     if (reqVerArray.length > 1)
  323.     {
  324.         var majorNum = parseInt(reqVerArray[0] );
  325.         if ( isNaN(majorNum) || majorNum < 2 )
  326.         {
  327.             shortVer = "1.0";
  328.         }
  329.         else
  330.         {
  331.             shortVer = reqVerArray[0]+'.'+reqVerArray[1];
  332.         }
  333.     }
  334.     
  335.     var verArg = "";
  336.     
  337.     if (shortVer.match(/^\d+\056\d+$/) )
  338.     {
  339.         verArg = "&v="+shortVer;
  340.     }
  341.     
  342.     Silverlight.followFWLink("114576" + verArg);
  343. }
  344.  
  345.  
  346. ///////////////////////////////////////////////////////////////////////////////////////////////
  347. /// Navigates to a url based on fwlinkid
  348. ///////////////////////////////////////////////////////////////////////////////////////////////
  349. Silverlight.followFWLink = function(linkid)
  350. {
  351.     top.location=Silverlight.fwlinkRoot+String(linkid);
  352. }
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365. ///////////////////////////////////////////////////////////////////////////////////////////////
  366. /// Encodes special characters in input strings as charcodes
  367. ///////////////////////////////////////////////////////////////////////////////////////////////
  368. Silverlight.HtmlAttributeEncode = function( strInput )
  369. {
  370.       var c;
  371.       var retVal = '';
  372.  
  373.     if(strInput == null)
  374.       {
  375.           return null;
  376.     }
  377.       
  378.       for(var cnt = 0; cnt < strInput.length; cnt++)
  379.       {
  380.             c = strInput.charCodeAt(cnt);
  381.  
  382.             if (( ( c > 96 ) && ( c < 123 ) ) ||
  383.                   ( ( c > 64 ) && ( c < 91 ) ) ||
  384.                   ( ( c > 43 ) && ( c < 58 ) && (c!=47)) ||
  385.                   ( c == 95 ))
  386.             {
  387.                   retVal = retVal + String.fromCharCode(c);
  388.             }
  389.             else
  390.             {
  391.                   retVal = retVal + '&#' + c + ';';
  392.             }
  393.       }
  394.       
  395.       return retVal;
  396. }
  397. ///////////////////////////////////////////////////////////////////////////////
  398. //
  399. //  Default error handling function to be used when a custom error handler is
  400. //  not present
  401. //
  402. ///////////////////////////////////////////////////////////////////////////////
  403.  
  404. Silverlight.default_error_handler = function (sender, args)
  405. {
  406.     var iErrorCode;
  407.     var errorType = args.ErrorType;
  408.  
  409.     iErrorCode = args.ErrorCode;
  410.  
  411.     var errMsg = "\nSilverlight error message     \n" ;
  412.  
  413.     errMsg += "ErrorCode: "+ iErrorCode + "\n";
  414.  
  415.  
  416.     errMsg += "ErrorType: " + errorType + "       \n";
  417.     errMsg += "Message: " + args.ErrorMessage + "     \n";
  418.  
  419.     if (errorType == "ParserError")
  420.     {
  421.         errMsg += "XamlFile: " + args.xamlFile + "     \n";
  422.         errMsg += "Line: " + args.lineNumber + "     \n";
  423.         errMsg += "Position: " + args.charPosition + "     \n";
  424.     }
  425.     else if (errorType == "RuntimeError")
  426.     {
  427.         if (args.lineNumber != 0)
  428.         {
  429.             errMsg += "Line: " + args.lineNumber + "     \n";
  430.             errMsg += "Position: " +  args.charPosition + "     \n";
  431.         }
  432.         errMsg += "MethodName: " + args.methodName + "     \n";
  433.     }
  434.     alert (errMsg);
  435. }
  436.  
  437. ///////////////////////////////////////////////////////////////////////////////////////////////
  438. /// Releases event handler resources when the page is unloaded
  439. ///////////////////////////////////////////////////////////////////////////////////////////////
  440. Silverlight.__cleanup = function ()
  441. {
  442.     for (var i = Silverlight._silverlightCount - 1; i >= 0; i--) {
  443.         window['__slEvent' + i] = null;
  444.     }
  445.     Silverlight._silverlightCount = 0;
  446.     if (window.removeEventListener) { 
  447.        window.removeEventListener('unload', Silverlight.__cleanup , false);
  448.     }
  449.     else { 
  450.         window.detachEvent('onunload', Silverlight.__cleanup );
  451.     }
  452. }
  453. ///////////////////////////////////////////////////////////////////////////////////////////////
  454. /// Releases event handler resources when the page is unloaded
  455. ///////////////////////////////////////////////////////////////////////////////////////////////
  456. Silverlight.__getHandlerName = function (handler)
  457. {
  458.     var handlerName = "";
  459.     if ( typeof handler == "string")
  460.     {
  461.         handlerName = handler;
  462.     }
  463.     else if ( typeof handler == "function" )
  464.     {
  465.         if (Silverlight._silverlightCount == 0)
  466.         {
  467.             if (window.addEventListener) 
  468.             {
  469.                 window.addEventListener('onunload', Silverlight.__cleanup , false);
  470.             }
  471.             else 
  472.             {
  473.                 window.attachEvent('onunload', Silverlight.__cleanup );
  474.             }
  475.         }
  476.         var count = Silverlight._silverlightCount++;
  477.         handlerName = "__slEvent"+count;
  478.         
  479.         window[handlerName]=handler;
  480.     }
  481.     else
  482.     {
  483.         handlerName = null;
  484.     }
  485.     return handlerName;
  486. }